package com.common.app.helper

import com.common.app.core.RouterHub
import com.common.app.data.bean.KeyBundle
import com.common.base.app.extras.*
import com.common.base.utils.AppUtils

/**
 * 作者：sosou
 * <p>
 * 版本：1.0
 * <p>
 * 创建日期：2022/8/25
 * <p>
 * 描述：
 * <p>
 * 修订历史：
 */
object LaunchHelper {

    fun launchLogin() {
        RouterHelper.navigationPostcard(RouterHub.ROUTER_LOGIN_ACTIVITY)
            .navigation()
    }

    fun launchSplash() {
        RouterHelper.navigationPostcard(RouterHub.ROUTER_SPLASH_ACTIVITY)
            .navigation()
    }
    fun launchMain() {
        RouterHelper.navigationPostcard(RouterHub.ROUTER_MAIN_ACTIVITY)
            .navigation()
    }

    //打开web
    fun launchWebActivity(
        path: String? = null,
        webData: String? = null,
        webTitle: String? = null,
        isShowToolBar: Boolean? = null,
        isStatusBarTranslate: Boolean? = null,
        mType: Int = 0,
    ) {
        (path.isNoEmpty() || webData.isNoEmpty()).yes {
            var showToolBar = isShowToolBar
            var statusBarTrans = isStatusBarTranslate

            if (showToolBar == null) {
                //没有指定是否显示标题栏 使用url中携带的配置参数
                showToolBar = AppUtils.toInt(
                    path?.getUrlParamValue("isHideTop"),
                    0
                ) == 0 //没配置isHideTop参数或者值为0 才显示标题栏
            }
            if (statusBarTrans == null) {
                //没有指定状态栏透明 使用url中携带的配置参数
                statusBarTrans =
                    AppUtils.toInt(path?.getUrlParamValue("isStatusBarTrans"), 0) == 1 //是否标题栏透明
            }

            RouterHelper.navigationPostcard(RouterHub.ROUTER_BASE_WEB_ACTIVITY)
                .withString(KeyBundle.PATH_URL, path)
                .withString(KeyBundle.WEB_DATA, webData)
                .withString(KeyBundle.WEB_TITLE, webTitle)
                .withInt(KeyBundle.WEB_TYPE, mType)
                .withBoolean(KeyBundle.WEB_SHOW_TOOLBAR, showToolBar ?: true)
                .withBoolean(KeyBundle.WEB_STATUS_BAR_TRANSLATE, statusBarTrans ?: false)
                .navigation()
        }
    }

}